import 'package:boss/models/takeout_summary.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/takeoutManagement/constant/takeout_status.dart';
import 'package:boss/ui/page/takeoutManagement/page/takeoutList/provider/takeout_list_provider.dart';
import 'package:boss/ui/widget/split_line.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TakeoutAggregateData extends StatelessWidget {
  final TakeoutSummary data;

  const TakeoutAggregateData({
    Key key,
    this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      textAlign: TextAlign.center,
      child: Container(
        margin: EdgeInsets.symmetric(
          horizontal: 20.w,
        ),
        padding: EdgeInsets.only(
          top: 34.w,
          bottom: 20.w,
        ),
        decoration: BoxDecoration(
          image: DecorationImage(
            image: ExactAssetImage('assets/image/takeout_bg.png'),
            fit: BoxFit.fill,
          ),
        ),
        child: Column(
          children: <Widget>[
            Text(
              '实收金额',
              style: TextStyleConstant().white_28,
            ),
            Container(
              margin: EdgeInsets.only(
                top: 36.w,
                bottom: 46.w,
              ),
              child: RichText(
                text: TextSpan(text: '¥', style: TextStyleConstant().white_28, children: [
                  TextSpan(
                      text: AmountUtil.price2String(data.summary ?? 0),
                      style: TextStyle(
                        fontSize: 50.sp,
                        color: Colors.white,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'DINAlternate-Bold',
                      )),
                ]),
              ),
            ),
            Row(
              children: <Widget>[
                buildMessage(
                    title: '已完成订单数',
                    value: data.orderCount.toString(),
                    onTap: () {
                      var provider = Provider.of<TakeoutListProvider>(
                        context,
                        listen: false,
                      );
                      provider.changeStatusList(TakeoutStatus.DETAIL_COMPLETED);
                    }),
                SplitLine(),
                buildMessage(
                    title: '异常订单数',
                    value: data.abnormalCount.toString(),
                    onTap: () {
                      var provider = Provider.of<TakeoutListProvider>(
                        context,
                        listen: false,
                      );
                      provider.changeStatusList(TakeoutStatus.DETAIL_ABNORMAL);
                    }),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget buildMessage({@required String title, @required String value, VoidCallback onTap}) {
    return Expanded(
      child: GestureDetector(
        onTap: onTap,
        child: Column(
          children: <Widget>[
            Text(value, style: TextStyleConstant().white_32),
            Container(
              margin: EdgeInsets.only(top: 15.w),
              child: Text(title, style: TextStyleConstant().white_26),
            ),
          ],
        ),
      ),
    );
  }
}
